package com.hdf.etdemo;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.easytools.dialog.ios.ActionSheetDialog;
import com.hdf.easytools.dialog.ios.AlertDialog;
import com.hdf.easytools.dialog.ios.ActionSheetDialog.OnSheetItemClickListener;
import com.hdf.easytools.dialog.ios.ActionSheetDialog.SheetItemColor;
import com.hdf.easytools.http.HttpUtil;
import com.hdf.easytools.loading.LoadingView;
import com.hdf.etdemo.dialog.DialogTypeActivity;
import com.hdf.etdemo.dialog.bigkoo.DialogActivity;
import com.hdf.etdemo.dialog.ios.IosDialogActivity;
import com.hdf.etdemo.friend.FriendActivity;
import com.hdf.etdemo.http.HttpActivity;
import com.hdf.etdemo.image.HeadImgActivity;
import com.hdf.etdemo.map.MapActivity;
import com.hdf.etdemo.notifications.NotificationsActivity;
import com.hdf.etdemo.uitl.TxtReader;
import com.hdf.etdemo.view.ListViewActivity;
import com.hdf.etdemo.view.badger.BadGerActivity;
import com.hdf.etdemo.view.listview.ViewPageListViewActivity;
import com.hdf.etdemo.view.loading.LoadingActivity;
import com.hdf.etdemo.view.progress.ProgressActivity;
import com.hdf.etdemo.view.section.SectionActivity;
import com.hdf.etdemo.view.sms.SmsActivity;
import com.hdf.etdemo.viewframe.SlidingtabActivity;
import com.hdf.etdemo.viewframe.ViewFrameActivity;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.umeng.update.UmengUpdateAgent;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends EasyToolsActivity {
	private Context context = MainActivity.this;

	/** 资源对象 */
	public Resources res;
	private ListView mainLv;
	private Adapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		
	}

	private void initView() {
		/** 设置标题显示 */
		this.TitleVisib(1, 0, 1, 0, 0);
		/** 绑定标题点击事件 */
		this.TitleClick(1, 0, 0, 0, 0);
		/** 设置标题样式ʽ */
		this.TitleStyle("关于", 0, "EasyTools", null, 0);
		TiTLeft.setTextColor(getResources().getColor(R.color.white));
		res = this.getResources();
		String str[] = res.getStringArray(R.array.maindata);
		List<String> data = new ArrayList<String>();
		for (int i = 0; i < str.length; i++) {
			data.add(str[i]);
		}
		adapter = new Adapter(context);
		adapter.setAppList(data);
		mainLv = (ListView) findViewById(R.id.mainlv);
		mainLv.setAdapter(adapter);
		mainLv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
				intent(arg2);
			}
		});
	}

	private void intent(int item) {
		if (item == 0)
			GoActivity(DialogTypeActivity.class);
		if (item == 1)
			GoActivity(ListViewActivity.class);
		if (item == 2)
			GoActivity(LoadingActivity.class);
		if (item == 3)
			GoActivity(ViewFrameActivity.class);
		if (item == 4)
			GoActivity(HeadImgActivity.class);
		if (item == 5)
			GoActivity(HttpActivity.class);
		if (item == 6)
			GoActivity(ProgressActivity.class);
		if (item == 7)
			GoActivity(BadGerActivity.class);
		if (item == 8)
			GoActivity(NotificationsActivity.class);
		if (item == 9)
			GoActivity(MapActivity.class);
		if (item == 10)
			GoActivity(SmsActivity.class);
		if (item == 11)
			GoActivity(FriendActivity.class);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.left_text:
			 GoActivity(AbloutActivity.class);
			//method3();
			break;

		default:
			break;
		}
	};

	private ProgressDialog pDialog;

	public void method3() {
		pDialog = ProgressDialog.show(this, "请稍等", "数据加载中");
		String urlString = "http://118.192.152.195:8080/version-msg/verions.xml";
		HttpUtil.get(urlString, new AsyncHttpResponseHandler() {
			@Override
			public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
				// TODO Auto-generated method stub
				Document doc = null;
				try {
					doc = (Document) DocumentHelper.parseText(new String(arg2));
				} catch (DocumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				Element et = doc.getRootElement();
				if(et.getStringValue().equals("1")){
					new AlertDialog(context).builder().setTitle("提示")
					.setMsg("发现新版本")
					.setPositiveButton("更新", new OnClickListener() {
						@Override
						public void onClick(View v) {

						}
					}).setNegativeButton("取消", new OnClickListener() {
						@Override
						public void onClick(View v) {

						}
					}).show();
				}
			}

			@Override
			public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
				// TODO Auto-generated method stub
				pDialog.dismiss();
			}
		});
	}
	
}
